﻿// CyGUI.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "CyGUI.h"
#include "CyGUIText.h"
#include "CyGUIButton.h"
#include "CyButton1.h"
#include <vector>
using namespace std;

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name

// Forward declarations of functions included in this code module:
INT_PTR CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR    lpCmdLine,
	int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	// TODO: Place code here.
	MSG          msg ;
	HWND         hwnd ;

	hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAINFORM), NULL, WndProc);

	ShowWindow (hwnd, nCmdShow) ;
	UpdateWindow (hwnd) ; 

	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage (&msg) ;
		DispatchMessage (&msg) ;
	}

	return (int) msg.wParam;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//

INT_PTR CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	try {
		INT wmId, wmEvent;
		PAINTSTRUCT ps;
		HDC hdc;
		CyGUIText * txt1;
		CyGUIButton * btn1;
		static CyButton1 * btnwarper;
		
		switch (message)
		{
		case WM_INITDIALOG:
			{
				btnwarper = new CyButton1(hWnd);
			}
			return TRUE;

		case WM_COMMAND:
			wmId    = LOWORD(wParam);
			wmEvent = HIWORD(wParam);
			// Parse the menu selections:
			switch (wmId)
			{
				//case IDM_ABOUT:
				//	DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
				//	return TRUE;

				//case IDM_EXIT:
				//	DestroyWindow(hWnd);
				//	return TRUE;

			case IDCANCEL:		
				PostQuitMessage (0) ;
				delete btnwarper;
				return TRUE;

			case IDOK:
				PostQuitMessage (0) ;
				delete btnwarper;
				return TRUE;

			default:
				return CyMessageProcessor::ProcessMessage(hWnd, message, wParam, lParam);
			}
			break;

		case WM_QUIT:
			
			break;
		default:
			return CyMessageProcessor::ProcessMessage(hWnd, message, wParam, lParam);
		}
	}
	catch (exception e)
	{
		MessageBoxA(hWnd, e.what(), "Unhandling exception", MB_OK);
		throw e;
	}

	return FALSE;
}


// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:

		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}

